package cn.tanglong.pay.service.impl;

import cn.tanglong.basic.service.impl.BaseServiceImpl;
import cn.tanglong.basic.util.LoginContextUtil;
import cn.tanglong.pay.dimain.PayBill;
import cn.tanglong.pay.service.IPayBillService;
import cn.tanglong.user.domain.Logininfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;

@Service
@Transactional
public class PayBillServiceImpl extends BaseServiceImpl<PayBill>
        implements IPayBillService {

    @Override
    public void save(Long businessKey, Integer businessType, String title, BigDecimal money,
                     Integer payChannel, Long shopId, String shopName, String payNo) {

        Logininfo loginContext = LoginContextUtil.getLoginContext();

        PayBill payBill = new PayBill();
        payBill.setDigest(title);
        payBill.setMoney(money);
        payBill.setState(PayBill.SATET_WAIT_PAY);
        payBill.setPayChannel(payChannel);
        payBill.setCreateTime(new Date());
        payBill.setUnionPaySn(payNo);
        payBill.setBusinessType(businessType);
        payBill.setBusinessKey(businessKey);
        payBill.setUser_id(loginContext.getId());
        payBill.setNickName(loginContext.getUsername());
        payBill.setShopName(shopName);
        payBill.setShop_id(shopId);
        add(payBill);
    }
}
